/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.common.utils.CommonUtil;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tenant.annotation.TenantIgnore;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.dto.ElevatorPrincipalQueryDTO;
import org.springblade.modules.admin.dto.ElevatorSaveDto;
import org.springblade.modules.admin.entity.*;
import org.springblade.modules.admin.mapper.es.ElevatorDocumentMapper;
import org.springblade.modules.admin.service.*;
import org.springblade.modules.admin.utils.GenerateElevatorNumService;
import org.springblade.modules.admin.vo.*;
import org.springblade.modules.admin.vo.ElevatorVO;
import org.springblade.modules.admin.vo.PlanConfigSearchVO;
import org.springblade.modules.admin.vo.TlwElevatorPageVO;
import org.springblade.modules.admin.vo.elevator.ElevatorIntactSearchVo;
import org.springblade.modules.admin.vo.elevator.ElevatorIntactVo;
import org.springblade.modules.system.entity.Dict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 电梯信息 控制器
 *
 * @author BladeX
 * @since 2021-05-11
 */
@RestController
@AllArgsConstructor
@RequestMapping("admin/elevator")
@Api(value = "电梯信息", tags = "电梯信息接口")
public class ElevatorController extends BladeController {

	@Autowired
	private ElevatorService elevatorService;

	@Autowired
	private IElevatorDetailService elevatorDetailService;

	@Autowired
	private IMaintainPlanContentService maintainPlanContentService;

	@Autowired
	private ElevatorDriveModeService elevatorDriveModeService;

	@Autowired
	private GenerateElevatorNumService gens;

	@Autowired
	private ElevatorDocumentMapper elevatorDocumentMapper;
	@Autowired
	private IElevatorContractService elevatorContractService;

	@Autowired
	private IBuildingContractPlusService buildingContractPlusService;

	@Autowired
	private IElevatorAttachmentService elevatorAttachmentService;

	@Autowired
	private IElevatorAttachmentHistoryService elevatorAttachmentHistoryService;


	@GetMapping("getElevatorPhones")
	public R<List<String>> getElevatorPhones() {
		return R.data(elevatorService.getElevatorPhones());
	}


	/**
	 * 新增 电梯
	 */
	@PostMapping()
	public R<Object> save(@RequestBody ElevatorSaveDto elevatorSaveDto) {
		return R.data(elevatorService.saveElevator(elevatorSaveDto));
	}

	/**
	 * 详情
	 */
	@TenantIgnore
	@GetMapping("/{id}")
	public R<ElevatorVO> detail(@PathVariable Long id) {
		ElevatorVO elevatorVO = elevatorService.selectElevator(id);
		return R.data(elevatorVO);
	}

	/**
	 * 分页,传入buildingId
	 */
	@GetMapping("")
	public R<IPage<ElevatorVO>> page(Elevator elevator, Query query, BladeUser bladeUser) {
		if (!bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID)) {
			elevator.setTenantId(bladeUser.getTenantId());
		}
		IPage<ElevatorVO> pages = elevatorService.selectElevatorPage(Condition.getPage(query), elevator);
		return R.data(pages);
	}

	/**
	 * 电梯完整度分页
	 * 分页,传入buildingId
	 */
	@PostMapping("page")
	@ApiOperation("电梯完整度分页")
	public R<IPage<ElevatorIntactVo>> pageList(@RequestBody ElevatorIntactSearchVo elevatorIntactSearchVo) {
		IPage<ElevatorIntactVo> pages = elevatorService.pageList(elevatorIntactSearchVo);
		return R.data(pages);
	}


	/**
	 * 修改
	 */
	@PutMapping("/{id}")
	@ApiOperation("修改电梯数据")
	public R<Boolean> update(@PathVariable Long id, @Valid @RequestBody ElevatorSaveDto elevatorSaveDto) {
		return R.status(elevatorService.updateElevator(id, elevatorSaveDto));
	}


	/**
	 * 修改
	 */
	@PostMapping("/update")
	public R<Boolean> update(@RequestBody Elevator elevator) {
		return R.status(elevatorService.updateById(elevator));
	}


	@PutMapping("/updateDeviceId/{id}")
	public R<Boolean> updateDevice(@PathVariable Long id, @Valid @RequestBody Elevator elevator) {
		elevator.setId(id);
		return R.status(elevatorService.updateById(elevator));
	}

	/**
	 * 删除
	 */
	@DeleteMapping()
	public R<Boolean> remove(@RequestParam String ids) {
		Long[] idArr = Convert.toLongArray(ids.split(",lp"));
		int count = maintainPlanContentService.count(Wrappers.<MaintainPlanContent>lambdaQuery().eq(MaintainPlanContent::getIsDeleted, 0).in(MaintainPlanContent::getElevatorId, idArr));
		if (count > 0) {
			throw new ServiceException("检查到电梯有排期计划,暂时无法删除");
		}
		count = elevatorContractService.count(Wrappers.<ElevatorContract>lambdaQuery().in(ElevatorContract::getElevatorId, Func.toLongList(ids)));
		if (count > 0) {
			throw new ServiceException("检查到电梯有合同,暂时无法删除");
		}

		// 执行删除
		if (elevatorService.deleteLogic(Func.toLongList(ids))) {
			// 根据 要删除的id,移除唯一识别码
			List<Long> elevatorIds = Func.toLongList(ids);
			// 根据 已删除的 电梯列表， 执行识别码回收
			elevatorIds.forEach(e -> {
				ElevatorDetail detail = elevatorDetailService.getOne(
					new LambdaQueryWrapper<ElevatorDetail>()
						.eq(ElevatorDetail::getElevatorId, e)
				);
				if (!Func.isNull(detail)) {
					String elevatorNum = detail.getElevatorNum();
					if (!Func.isNull(elevatorNum)) {
						gens.removeElevatorNum(elevatorNum);
					}
				}
				// 删除es
				elevatorDocumentMapper.deleteById(e);
				elevatorDetailService.remove(Wrappers.<ElevatorDetail>lambdaQuery().eq(ElevatorDetail::getElevatorId, e));
				// 2024-05-25 删除附件及附件历史
				List<ElevatorAttachment> attachmentList = elevatorAttachmentService.list(Wrappers.<ElevatorAttachment>lambdaQuery().eq(ElevatorAttachment::getElevatorId, e));
				elevatorAttachmentService.removeByIds(attachmentList.stream().map(ElevatorAttachment::getId).collect(Collectors.toList()));
				List<ElevatorAttachmentHistory> historyList = elevatorAttachmentHistoryService.list(Wrappers.<ElevatorAttachmentHistory>lambdaQuery().eq(ElevatorAttachmentHistory::getElevatorId, e));
				elevatorAttachmentHistoryService.removeByIds(historyList.stream().map(ElevatorAttachmentHistory::getId).collect(Collectors.toList()));
			});

			return R.status(true);

		}
		return R.status(false);
	}

	/**
	 * 检查电梯设备编码
	 *
	 * @param privateNum
	 * @return
	 */
	@GetMapping("/checkPrivateNum")
	public R checkPrivateNum(@RequestParam("privateNum") String privateNum, @RequestParam("id") Long id, @RequestParam("type") String type) {
		if (Func.notNull(privateNum) && !"".equals(privateNum)) {
			ElevatorVO elevatorVO = elevatorService.selectElevByPrivateNum(privateNum, null);
			if (Func.notNull(elevatorVO)) {
				// 当前前端操作为修改时 判断设备代码是否为本梯在用
				if ("update".equals(type) && id.equals(elevatorVO.getId())) {
					return R.success("设备编码可以使用");
				}
				String address = elevatorVO.getBuildingName() + "-" + elevatorVO.getElevatorAddress();
				return R.fail(402, "与" + address + "相同，请更换");
			}
		}

		return R.success("设备编码可以使用");
	}

	/**
	 * 获取驱动下拉框数据
	 *
	 * @return
	 */
	@GetMapping("/getDriveModeSelect")
	public R<List<ElevatorDriveMode>> getDriveModeSelect() {
		return R.data(elevatorDriveModeService.getDriveModeSelect());
	}

	/**
	 * 获取驱动下拉框数据
	 *
	 * @return
	 */
	@GetMapping("/list/of/buildingId")
	public R<List<ElevatorDetail>> getListByBuildingId(Long buildingId) {
		return R.data(elevatorService.getListByBuildingId(buildingId, null));
	}

	/**
	 * 获取驱动下拉框数据
	 *
	 * @return
	 */
	@GetMapping("/list/of/buildingIds/v2")
	public R<List<BuildingElevatorSimpleInfoVO>> getListByBuildingIdsV2(String buildingIds) {

		List<BuildingElevatorSimpleInfoVO> resultList = new ArrayList<>(16);
		final String[] ids = buildingIds.split(",");
		List<ElevatorDetail> eleList = new ArrayList<>();
		for (String id : ids) {
			List<ElevatorDetail> list = elevatorService.getListByBuildingId(Convert.toLong(id), null);
			eleList.addAll(list);
		}
		Map<String, List<ElevatorDetail>> map = eleList.stream().collect(Collectors.groupingBy(ElevatorDetail::getBuildingName));
		List<String> buildingNames = eleList.stream().map(ElevatorDetail::getBuildingName).distinct().collect(Collectors.toList());
		for (String str : buildingNames) {
			BuildingElevatorSimpleInfoVO buildingElevatorSimpleInfoVO = new BuildingElevatorSimpleInfoVO();
			buildingElevatorSimpleInfoVO.setBuildingName(str);
			List<ElevatorDetail> elevatorDetails = map.get(str);
			if (elevatorDetails == null || elevatorDetails.size() == 0) {
				continue;
			}
			List<ElevatorSimpleInfoVO> elevatorInfos = new ArrayList<>();
			for (ElevatorDetail elevatorDetail : elevatorDetails) {
				ElevatorSimpleInfoVO elevatorSimpleInfoVO = new ElevatorSimpleInfoVO();
				elevatorSimpleInfoVO.setElevatorAddress(elevatorDetail.getElevatorAddress());
				elevatorSimpleInfoVO.setElevatorId(elevatorDetail.getElevatorId());
				elevatorInfos.add(elevatorSimpleInfoVO);
			}
			buildingElevatorSimpleInfoVO.setElevatorInfos(elevatorInfos);
			resultList.add(buildingElevatorSimpleInfoVO);
		}
		return R.data(resultList);
	}

	@TenantIgnore
	@GetMapping("/select/list")
	@ApiOperation(value = "获取电梯下拉列表（忽略租户）")
	public R<List<ElevatorSimpleInfoVO>> elevatorSelectList(@ApiParam(value = "项目id", required = true) @RequestParam Long buildingId) {
		return R.data(elevatorService.elevatorSelectList(buildingId));
	}

	@TenantIgnore
	@GetMapping("/select/list/v2")
	@ApiOperation(value = "获取电梯下拉列表（忽略租户）")
	public R<List<ElevatorSimpleInfoVO>> elevatorSelectListV2(@ApiParam(value = "项目id", required = true) @RequestParam String buildingIds) {
		List<ElevatorSimpleInfoVO> list = new ArrayList<>();
		String[] split = buildingIds.split(",");
		for (String buildingId : split) {
			final List<ElevatorSimpleInfoVO> elevatorSimpleInfoVOS = elevatorService.elevatorSelectList(Convert.toLong(buildingId));
			list.addAll(elevatorSimpleInfoVOS);
		}
		return R.data(list);
	}

	@TenantIgnore
	@GetMapping("/tlw/select/list")
	@ApiOperation(value = "梯联网-获取电梯下拉列表（忽略租户）")
	public R<List<ElevatorSimpleInfoVO>> elevatorTlwSelectList(PlanConfigSearchVO search) {
		return R.data(elevatorService.elevatorTlwSelectList(search));
	}


	@TenantIgnore
	@GetMapping("/tlw/detail/{elevatorId}")
	public R<TlwElevatorDetailVO> getTlwElevatorDetail(@PathVariable Long elevatorId) {
		return R.data(elevatorService.getTlwElevatorDetail(elevatorId));
	}

	@TenantIgnore
	@PostMapping("/tlw/page")
	@ApiOperation(value = "梯联网-获取电梯分页列表（忽略租户）")
	public R<IPage<TlwElevatorPageVO>> tlwPage(@RequestBody PlanConfigSearchVO search, @RequestBody Query query) {
		return R.data(elevatorService.tlwPage(search, Condition.getPage(query)));
	}

	@TenantIgnore
	@GetMapping("/tlw/select-device/list")
	@ApiOperation(value = "梯联网-获取电梯分页列表（忽略租户）")
	public R<List<TlwElevatorPageVO>> selectDevice(@RequestParam(required = false) String deviceId) {
		return R.data(elevatorService.selectElevatorByDeviceId(deviceId));
	}

	@TenantIgnore
	@GetMapping("/batch/download/wxappcode")
	@ApiOperation(value = "批量下载电梯码")
	public R<List<WxAppCodeVO>> batchDownloadWxAppCode(@RequestParam(name = "电梯id，多个逗号隔开") String elevatorIds) {
		return R.data(elevatorService.batchDownloadWxAppCode(Func.toLongList(elevatorIds)));
	}

	@TenantIgnore
	@GetMapping("/generateWxAppCode")
	@ApiOperation("获取小程序码")
	public R generateWxAppCode(@RequestParam(value = "elevatorId") Long elevatorId) {
		String codeUrl = elevatorService.generateWxAppCode(elevatorId);
		return R.data(codeUrl);
	}

	@GetMapping("/elevator/dossier/page")
	@ApiOperation(value = "电梯档案-列表")
	public R<IPage<ElevatorDossierVO>> elevatorDossierPage(ElevatorVO elevator, Query query, BladeUser bladeUser) {
		if (!bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID)) {
			elevator.setTenantId(bladeUser.getTenantId());
		}
		return R.data(elevatorService.elevatorDossierPage(Condition.getPage(query), elevator));

	}

	/**
	 * @return
	 * @Author lsay
	 * @Description {
	 * 电梯档案-统计
	 * }
	 * @Date 8:59 2023/5/8
	 * @Param
	 **/
	@GetMapping("/elevator/dossier/count")
	public R<Map<String, Object>> elevatorDossierCount() {
		return R.data(elevatorService.elevatorDossierCount());
	}

	@GetMapping("/elevator/dossier/select/list")
	@ApiOperation(value = "获取电梯下拉列表")
	public R<List<ElevatorSimpleInfoVO>> elevatorTlwSelectList(PlanConfigSearchVO search, BladeUser bladeUser) {
		if (!bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID)) {
			search.setTenantId(bladeUser.getTenantId());
		}
		return R.data(elevatorService.elevatorTlwSelectList(search));
	}

	/**
	 * @return
	 * @Author lsay
	 * @Description {
	 * 电梯责任管理分页
	 * }
	 * @Date 10:22 2023/2/10
	 * @Param
	 **/
	@PostMapping("/principal/page")
	public R<IPage<ElevatorPrincipalPageVO>> elevatorPrincipalPage(@RequestBody ElevatorPrincipalQueryDTO queryDTO, @RequestBody Query query) {
		IPage<ElevatorPrincipalPageVO> pages = elevatorService.selectElevatorPrincipalPage(Condition.getPage(query), queryDTO);
		return R.data(pages);
	}

	/**
	 * @return
	 * @Author lsay
	 * @Description {
	 * 电梯责任管理统计
	 * }
	 * @Date 10:22 2023/2/10
	 * @Param
	 **/
	@GetMapping("/principal/count")
	public R<Map<String, Integer>> elevatorPrincipalCount() {
		return R.data(elevatorService.selectElevatorPrincipalCount());
	}

	/**
	 * @return
	 * @Author lsay
	 * @Description {
	 * 校验电梯责任组和责任人所在组是否相同
	 * }
	 * @Date 15:14 2023/2/15
	 * @Param
	 **/
	@GetMapping("/principal/check/dept/user")
	public R<Boolean> elevatorPrincipalCheckDeptUser(String deptId, String userIds) {
		return R.data(elevatorService.checkPrincipalDeptUser(deptId, userIds));
	}

	@GetMapping("/init")
	@ApiOperation(value = "数据初始化-更新合同状态")
	public R<String> init() {
		List<Elevator> elevators = elevatorService.list();
		for (Elevator elevator : elevators) {
			List<ElevatorContract> list = elevatorContractService.getList(elevator.getId());
			if (list.size() == 0) {
				elevator.setFirstContractStatus(1);
			} else {
				ElevatorContract elevatorContract = list.get(0);
				BuildingContractPlus contractPlus = buildingContractPlusService.getById(elevatorContract.getContractId());
				Integer anInt = Convert.toInt(contractPlus.getContractSource(), -5);
				if (contractPlus.getStatus() == 1) {
					elevator.setContractPassStatus(1);
				} else {
					elevator.setContractPassStatus(0);
				}
				if (anInt == 1) {
					elevator.setFirstContractStatus(2);
				}
				if (anInt == 5) {
					elevator.setFirstContractStatus(3);
				}
				if (anInt == 6) {
					elevator.setFirstContractStatus(4);
				}
			}
		}
		List<List<Elevator>> partition = Lists.partition(elevators, 20);
		for (List<Elevator> li : partition) {
			elevatorService.updateBatchById(li);
		}

		return R.data("数据初始化成功");
	}

	/**
	 * @return
	 * @Author lsay
	 * @Description {
	 * 检查电梯年审类型是否允许修改
	 * }
	 * @Date 19:18 2023/5/8
	 * @Param
	 **/
	@GetMapping("/check/audit/type")
	public R<Boolean> elevatorCheckAuditType(Long elevatorId, Integer useType) {
		return R.data(elevatorService.elevatorCheckAuditType(elevatorId, useType));
	}

	/**
	 * @return
	 * @Author lsay
	 * @Description {
	 * 获取电梯设备技术参数下拉选择值
	 * }
	 * @Date 16:11 2023/8/12
	 * @Param
	 **/
	@TenantIgnore
	@GetMapping("/driver/mode/field/select")
	public R<List<Dict>> driverModeFieldSelect(String code, String driverModeCode, String driverModeKey) {
		return R.data(elevatorService.driverModeFieldSelect(code, driverModeCode, driverModeKey));
	}

	@TenantIgnore
	@GetMapping("/test/detail/field/v")
	public R<?> testDetailFieldV() {
		return R.data(elevatorService.testDetailFieldV());
	}

	@TenantIgnore
	@ApiOperation(value = "梯联网-显示屏-电梯基础信息")
	@GetMapping("/tlw/screen/elevator/base/info")
	public R<TlwScreenEleBaseInfoVO> tlwScreenEleBaseInfo(@RequestParam String deviceId) {
		return R.data(elevatorService.tlwScreenEleBaseInfo(deviceId));
	}

	@TenantIgnore
	@GetMapping("/init/elevator/maintain/day")
	public R<?> initElevatorMaintainDay() {
		elevatorService.updateElevatorMaintainStatusDay();
		return R.data(Boolean.TRUE);
	}

	@TenantIgnore
	@GetMapping("/init/maintain/day")
	public R<?> initMaintainDay() {
		return R.data(elevatorService.initMaintainDay());
	}


	@ApiOperation(value = "根据ids获取品牌")
	@GetMapping("getBrandListOfElevatorIds")
	public R<List<ElevatorBrand>> getBrandListOfElevatorId(String elevatorIds) {
		return R.data(elevatorService.getBrandListOfElevatorId(elevatorIds));
	}

	@ApiOperation(value = "完整度初始化")
	@GetMapping("elevator/init")
	public R<String> elevatorInit() {
		elevatorService.elevatorInit(null);
		return R.data("数据处理完成");
	}


	/**
	 * 电梯完整度分页
	 * 分页,传入buildingId
	 */
	@PostMapping("down/intact")
	@ApiOperation("电梯完整度Excel分页")
	public void downIntact(HttpServletResponse response, @RequestBody ElevatorIntactSearchVo elevatorIntactSearchVo) throws IOException {
		elevatorIntactSearchVo.setSize(0);
		List<ElevatorIntactVo> records = elevatorService.pageList(elevatorIntactSearchVo).getRecords();
		ExcelWriter excelWriter = null;
		ServletOutputStream outputStream = response.getOutputStream();
		try {
			List<List<String>> rows = new ArrayList<>();
			List<String> title = CollUtil.newArrayList
				("类型", "项目名称", "电梯位置", "电梯年检类型", "类型与位置(%)", "维保信息(%)", "保险信息(%)", "结构类型(%)", "设备技术参数(%)",
					"设备注册信息(%)", "出厂信息(%)", "使用信息(%)", "梯无忧平台信息(%)", "最后更新时间", "维保负责人");
			rows.add(title);
			for (ElevatorIntactVo elevatorIntactVo : records) {
				List<String> row = new ArrayList<>(16);
				row.add(Convert.toStr(elevatorIntactVo.getTypeName(), "/"));
				row.add(Convert.toStr(elevatorIntactVo.getBuildingName(), "/"));
				row.add(Convert.toStr(elevatorIntactVo.getElevatorAddress(), "/"));
				row.add(Convert.toInt(elevatorIntactVo.getUseType(), 0) == 0 ? "年审" : "非年审");
				row.add(Convert.toStr(elevatorIntactVo.getLwIntact().compareTo(BigDecimal.ZERO) != 0 ? Convert.toInt(elevatorIntactVo.getLwIntact().multiply(Convert.toBigDecimal(100))) : 0));
				row.add(Convert.toStr(elevatorIntactVo.getWbIntact().compareTo(BigDecimal.ZERO) != 0 ? Convert.toInt(elevatorIntactVo.getWbIntact().multiply(Convert.toBigDecimal(100))) : 0));
				row.add(Convert.toStr(elevatorIntactVo.getBxIntact().compareTo(BigDecimal.ZERO) != 0 ? Convert.toInt(elevatorIntactVo.getBxIntact().multiply(Convert.toBigDecimal(100))) : 0));
				row.add(Convert.toStr(elevatorIntactVo.getJgIntact().compareTo(BigDecimal.ZERO) != 0 ? Convert.toInt(elevatorIntactVo.getJgIntact().multiply(Convert.toBigDecimal(100))) : 0));
				row.add(Convert.toStr(elevatorIntactVo.getSbJsIntact().compareTo(BigDecimal.ZERO) != 0 ? Convert.toInt(elevatorIntactVo.getSbJsIntact().multiply(Convert.toBigDecimal(100))) : 0));
				row.add(Convert.toStr(elevatorIntactVo.getSbZcIntact().compareTo(BigDecimal.ZERO) != 0 ? Convert.toInt(elevatorIntactVo.getSbZcIntact().multiply(Convert.toBigDecimal(100))) : 0));
				row.add(Convert.toStr(elevatorIntactVo.getCcIntact().compareTo(BigDecimal.ZERO) != 0 ? Convert.toInt(elevatorIntactVo.getCcIntact().multiply(Convert.toBigDecimal(100))) : 0));
				row.add(Convert.toStr(elevatorIntactVo.getSyIntact().compareTo(BigDecimal.ZERO) != 0 ? Convert.toInt(elevatorIntactVo.getSyIntact().multiply(Convert.toBigDecimal(100))) : 0));
				row.add(Convert.toStr(elevatorIntactVo.getTwyIntact().compareTo(BigDecimal.ZERO) != 0 ? Convert.toInt(elevatorIntactVo.getTwyIntact().multiply(Convert.toBigDecimal(100))) : 0));
				row.add(DateUtil.format(elevatorIntactVo.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"));
				row.add(Convert.toStr(elevatorIntactVo.getUserNames(), "/"));
				rows.add(row);
			}
			String fileName = DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".xlsx";
			CommonUtil.setResponseHeader(response, fileName);
			excelWriter = ExcelUtil.getBigWriter(rows.size());
			excelWriter.write(rows, true);
			excelWriter.flush(outputStream, true);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (excelWriter != null) {
				excelWriter.close();
			}
			outputStream.close();
		}

	}

}
